package com.tutu.controller.backend;

import com.tutu.common.DataTableFactory;
import com.tutu.controller.common.CommonController;
import com.tutu.service.EmissionCodeService;
import com.tutu.utils.WebUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 排放因子管理
 */
@Controller
@RequestMapping(value = "backend/emissionCode")
public class EmissionCodeController extends CommonController {

    public static List<Map<String, Object>> emissionCodeList = new ArrayList<>();

    @Autowired
    EmissionCodeService emissionCodeService;

    @RequestMapping(value = "/index")
    public String index() {
        return "backend/emissionCode/list";
    }

    @RequestMapping("/list")
    public void list(HttpServletResponse response, Integer type, String keyWord, Integer draw, Integer start, Integer length) {
        int pageNum = getPageNum(start, length);

        Map<String, Object> result = DataTableFactory.fitting(draw, emissionCodeService.pageByParams(type, keyWord, pageNum, length));

        WebUtil.printJson(response, result);
    }

    @RequestMapping("/save")
    @ResponseBody
    public Map<String, Object> save(HttpServletRequest request, Integer id, Integer type, String content) {
        return emissionCodeService.saveInfo(request, id, type, content);
    }

    @RequestMapping("/del")
    @ResponseBody
    public Map<String, Object> del(HttpServletRequest request, Integer id) {
        return emissionCodeService.deleteById(request, id);
    }

    @RequestMapping("/batchDel")
    @ResponseBody
    public Map<String, Object> batchDel(HttpServletRequest request, String ids) {
        return emissionCodeService.batchDel(request, ids);
    }
}